using HKB.Common;
using System;
using System.Data;
using System.Web;
namespace HKB.Web
{
	public class Shop_Module
	{
		private Conn conn;
		public Shop_Module(Conn _conn)
		{
			this.conn = _conn;
		}
		public Shop_Module()
		{
			this.conn = Text.GetComponent<Conn>("conn", HttpContext.Current.CurrentHandler);
		}
		public DataTable GetAllModule()
		{
			return this.conn.GetDataTable("SELECT * From [HLShop_Module] Order By ID Desc");
		}
		public DataTable GerActiveIdTitle()
		{
			return this.conn.GetDataTable("SELECT Id, Title From [HLShop_Module] Where Status=1 Order By ID Desc");
		}
		public DataTable GetModuleById(int id)
		{
			DataTable result;
			if (id > 0)
			{
				IDbDataParameter dbDataParameter = this.conn.CreateParameter("@ID", DbType.Int32, id);
				result = this.conn.GetDataTable("SELECT * From [HLShop_Module] Where ([ID] = @ID)", new IDbDataParameter[]
				{
					dbDataParameter
				});
			}
			else
			{
				result = null;
			}
			return result;
		}
		public DataTable GetModuleByName(string Name)
		{
			DataTable result;
			if (!string.IsNullOrEmpty(Name))
			{
				IDbDataParameter dbDataParameter = this.conn.CreateParameter("@name", DbType.String, Name);
				result = this.conn.GetDataTable("SELECT * From [HLShop_Module] Where ([name] = @name)", new IDbDataParameter[]
				{
					dbDataParameter
				});
			}
			else
			{
				result = null;
			}
			return result;
		}
		public bool AddModule(int id, string IDName, string CssName, string ContentTemplate, string Layout, string MoreLinkUrl, string name, int NeedMoreLink, int NeedSummary, int NeedTitleHead, string Summary, string Title, string TitleLink, int Status)
		{
			IDbDataParameter[] parameters = new IDbDataParameter[]
			{
				this.conn.CreateParameter("@name", DbType.AnsiString, name),
				this.conn.CreateParameter("@IDName", DbType.AnsiString, IDName),
				this.conn.CreateParameter("@CssName", DbType.AnsiString, CssName),
				this.conn.CreateParameter("@NeedTitleHead", DbType.Int32, NeedTitleHead),
				this.conn.CreateParameter("@Title", DbType.AnsiString, Title),
				this.conn.CreateParameter("@TitleLink", DbType.AnsiString, TitleLink),
				this.conn.CreateParameter("@NeedMoreLink", DbType.Int32, NeedMoreLink),
				this.conn.CreateParameter("@MoreLinkUrl", DbType.AnsiString, MoreLinkUrl),
				this.conn.CreateParameter("@NeedSummary", DbType.Int32, NeedSummary),
				this.conn.CreateParameter("@Summary", DbType.AnsiString, Summary),
				this.conn.CreateParameter("@Layout", DbType.AnsiString, Layout),
				this.conn.CreateParameter("@ContentTemplate", DbType.AnsiString, ContentTemplate),
				this.conn.CreateParameter("@Status", DbType.Int32, Status)
			};
			int num = this.conn.Execute("INSERT INTO [HLShop_Module] ([name], [IDName], [CssName], [NeedTitleHead], [Title], [TitleLink], [NeedMoreLink], [MoreLinkUrl], [NeedSummary], [Summary], [Layout], [ContentTemplate], [Status]) VALUES (@name, @IDName, @CssName, @NeedTitleHead, @Title, @TitleLink, @NeedMoreLink, @MoreLinkUrl, @NeedSummary, @Summary, @Layout, @ContentTemplate, @Status)", parameters);
			return num == 1;
		}
		public bool UpdateModule(string IDName, string CssName, string ContentTemplate, string Layout, string MoreLinkUrl, string name, int NeedMoreLink, int NeedSummary, int NeedTitleHead, string Summary, string Title, string TitleLink, int Status, int id)
		{
			IDbDataParameter[] parameters = new IDbDataParameter[]
			{
				this.conn.CreateParameter("@name", DbType.AnsiString, name),
				this.conn.CreateParameter("@IDName", DbType.AnsiString, IDName),
				this.conn.CreateParameter("@CssName", DbType.AnsiString, CssName),
				this.conn.CreateParameter("@NeedTitleHead", DbType.Int32, NeedTitleHead),
				this.conn.CreateParameter("@Title", DbType.AnsiString, Title),
				this.conn.CreateParameter("@TitleLink", DbType.AnsiString, TitleLink),
				this.conn.CreateParameter("@NeedMoreLink", DbType.Int32, NeedMoreLink),
				this.conn.CreateParameter("@MoreLinkUrl", DbType.AnsiString, MoreLinkUrl),
				this.conn.CreateParameter("@NeedSummary", DbType.Int32, NeedSummary),
				this.conn.CreateParameter("@Summary", DbType.AnsiString, Summary),
				this.conn.CreateParameter("@Layout", DbType.AnsiString, Layout),
				this.conn.CreateParameter("@ContentTemplate", DbType.AnsiString, ContentTemplate),
				this.conn.CreateParameter("@Status", DbType.Int32, Status),
				this.conn.CreateParameter("@Original_id", DbType.Int32, id)
			};
			int num = this.conn.Execute("UPDATE [HLShop_Module] SET [name] = @name, [IDName] = @IDName, [CssName] = @CssName, [NeedTitleHead] = @NeedTitleHead, [Title] = @Title, [TitleLink] = @TitleLink, [NeedMoreLink] = @NeedMoreLink, [MoreLinkUrl] = @MoreLinkUrl, [NeedSummary] = @NeedSummary, [Summary] = @Summary, [Layout] = @Layout, [ContentTemplate] = @ContentTemplate, [Status] = @Status WHERE (([id] = @Original_id))", parameters);
			return num == 1;
		}
		public bool DelModule(int id)
		{
			IDbDataParameter dbDataParameter = this.conn.CreateParameter("@ID", DbType.Int32, id);
			int num = this.conn.Execute("DELETE From [HLShop_Module] Where ([ID] = @ID)", new IDbDataParameter[]
			{
				dbDataParameter
			});
			return num == 1;
		}
	}
}
